//
//  Shader.fsh
//  Renderbunny
//
//  Created by Holmes Futrell on 1/20/11.
//  Copyright 2011 Holmes Futrell. All rights reserved.
//

uniform sampler2D sampler;

uniform vec2 invSize;

uniform bool alphaOnly;

varying vec2 uv;

void main()
{
	if (alphaOnly) {
	
		float alpha = texture2D(sampler, uv).a;
		gl_FragColor = vec4(alpha, alpha, alpha, 1.0);
		
	}
	else {
		vec3 color = texture2D(sampler, uv).rgb;
		
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(-1.0, -1.0)).rgb;
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(1.0, -1.0)).rgb;
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(-1.0, 1.0)).rgb;
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(1.0, 1.0)).rgb;
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(0.0, -1.0)).rgb;
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(1.0, 0.0)).rgb;
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(-1.0, 0.0)).rgb;
		color += 0.5 * texture2D(sampler, uv + invSize * vec2(1.0, 0.0)).rgb;

		gl_FragColor = vec4(color.x, color.y, color.z, 1.0);

	}
}